function main(defaultParams) {
    const self = this;
    debugger

    let cardStateCode = defaultParams.card_state_code.value

    if (defaultParams.callbackParams) {
        var validFlag = defaultParams.callbackParams.data.root_8hq6z0.radio_4bwikf;
        var confiscatedCardInfoId = defaultParams.callbackParams.data.root_8hq6z0.number_input_bo160u;
        let approvalStateCode = 2;
        let approvalStateName = '';
        let card_state_code = 1;
        let stateCode = 1;

        // 根据 cardStateCode 确定审批类型
        let approvalType = getApprovalTypeByCardState(cardStateCode);
        console.log("当前cardStateCode:", cardStateCode, "对应的审批类型:", approvalType);

        // 审核是否通过
        if (validFlag == '1') {
            stateCode = 3;
            card_state_code = getNextCardStateCode(cardStateCode);
            approvalStateCode = 1;
            approvalStateName = '通过';

            // 审核通过，插入终审记录
            let approvalData = {
                confiscatedCardId: confiscatedCardInfoId,
                unitId: '1',
                unitName: '宁夏回族自治区',
                humanId: '30062',
                humanName: '王娟',
                approvalStateCode: "1",
                approvalType: approvalType,
                opinion: "终审通过",
                stageId: 3,
                stageName: "终审"
            }
            insertLawConfiscatedCardApprovalInfo(approvalData).then(res => {
                console.log("终审记录插入成功");
            });
        } else {
            stateCode = 1;
            card_state_code = cardStateCode;
            approvalStateName = '不通过';
            approvalStateCode = 2;

        }

        var id = defaultParams.callbackParams.data.root_8hq6z0.number_input_bo160u;
        var update = "UPDATE('ds_tbl:t_78e3820cec034204b3ec0f507253f5de',QUERY_EQ('id','" + id + "'),'', ['state_code','" + stateCode + "','card_state_code','" + card_state_code + "','approval_state_code','" + approvalStateCode + "', 'approval_state_name',' " + approvalStateName + " ','issuance_time', NOW()])";

        api.EXEC_FORMULA(update).then((res) => {
            console.log("主表状态更新成功");
            // 获取页面列表组件
            var pageListEle = self.$$("page_widget_list_f968i3");
            // 获取列表渲染页实例
            var listRenderView = pageListEle.$$getRenderElement();
            // 获取当前显示的组件，表格或者卡片
            var currentListEle = listRenderView.$$getListElement();
            // 调用刷新方法
            currentListEle.$$refreshData();
        }).catch(err => {
            console.error("状态更新失败:", err);
        });
    }
}

/**
 * 根据cardStateCode获取对应的审批类型
 * @param {string} cardStateCode
 * @returns {string} 审批类型
 */
function getApprovalTypeByCardState(cardStateCode) {
    switch(String(cardStateCode)) {
        case '1': // 申请中
            return "1"; // 申请
        case '5': // 变更中
            return "2"; // 变更
        case '4': // 注销中
            return "3"; // 注销
        default:
            return "1"; // 默认申请类型
    }
}

/**
 * 根据当前状态获取审核通过后的下一个状态
 * @param {string} currentCardStateCode
 * @returns {string} 下一个状态码
 */
function getNextCardStateCode(currentCardStateCode) {
    switch(String(currentCardStateCode)) {
        case '1': // 申请中 -> 制证中
            return '2';
        case '5': // 变更中 -> 制证中（重新制证）
            return '2';
        case '4': // 注销中 -> 已注销
            return '4'; // 或者根据业务需求调整
        default:
            return '2'; // 默认制证中
    }
}

/**
 * 插入罚没证审批信息
 * @param {object} approvalData 审批数据
 * @returns {Promise}
 */
function insertLawConfiscatedCardApprovalInfo(approvalData) {
    const insertLawConfiscatedCardApprovalInfoSql = [
        ['confiscated_card_id', approvalData.confiscatedCardId],
        ['unit_id', "'" + approvalData.unitId + "'"],
        ['unit_name', "'" + approvalData.unitName + "'"],
        ['human_id', "'" + approvalData.humanId + "'"],
        ['human_name', "'" + approvalData.humanName + "'"],
        ['approval_state_code', "'" + approvalData.approvalStateCode + "'"],
        ['opinion', "'" + approvalData.opinion + "'"],
        ['approval_type', "'" + approvalData.approvalType + "'"],
        ['STAGE_ID', "'" + (approvalData.stageId || 3) + "'"],
        ['STAGE_NAME', "'" + (approvalData.stageName || "终审") + "'"],
        ['approval_time', 'NOW()']
    ];

    let law_confiscated_card_approval_info = 'ds_tbl:t_d6d40a9fbcac40568e164e9976b35459';

    // 构建参数化INSERT语句
    const formattedFields = insertLawConfiscatedCardApprovalInfoSql.map(function (field) {
        return "'" + field[0] + "'," + field[1];
    });

    const insertSql = "INSERT('" + law_confiscated_card_approval_info + "', [" + formattedFields.join(',') + "])";
    console.log("准备执行的SQL语句:", insertSql);

    return new Promise(function (resolve, reject) {
        api.EXEC_FORMULA(insertSql)
            .then(function (res) {
                console.log("审批记录插入成功");
                resolve(res);
            })
            .catch(function (err) {
                console.error("审批记录插入失败:", err);
                reject(new Error(`审批记录插入失败: ${err.message}`));
            });
    });
}
